package com.iyjhsoc.game.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.iyjhsoc.game.dao.CompetitionDAO;
import com.iyjhsoc.game.domain.VO.CompetitionVO;
import com.iyjhsoc.game.domain.entity.CompetitionDO;
import com.iyjhsoc.game.domain.response.Response;
import com.iyjhsoc.game.service.CompetitionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CompetitionServiceImpl extends ServiceImpl<CompetitionDAO,CompetitionDO> implements CompetitionService  {
    @Resource
    CompetitionDAO competitionDAO;
    @Override
    public Response saveDual(CompetitionDO dualDO) {
        int insert = competitionDAO.insert(dualDO);
        return insert>0?Response.SUCCESS():Response.ERROR("保存失败");
    }

    @Override
    public Response updateDual(CompetitionDO dualDO) {
        int i = competitionDAO.updateById(dualDO);
        return i>0?Response.SUCCESS():Response.ERROR("修改失败");
    }

    @Override
    public Response queryList(CompetitionVO vo) {
        PageHelper.startPage(vo.getPageNum(),vo.getPageSize());
        List<CompetitionVO> competitionVOS = competitionDAO.queryList(vo);
        return Response.SUCCESS(new PageInfo(competitionVOS));
    }

    @Override
    public Response selectById(String id) {
        CompetitionDO competitionDO = competitionDAO.selectById(id);
        return Response.SUCCESS(competitionDO);
    }

    @Override
    public Response getNotStartCompetition(CompetitionVO vo) {
        PageHelper.startPage(vo.getPageNum(),vo.getPageSize());
        List<CompetitionDO> competitionVOS = competitionDAO.queryNotStart(vo);
        return Response.SUCCESS(competitionVOS);
    }
}
